#ifndef __THREAD_POOL__
#define __THREAD_POOL__
//----------------------------------------------------------------
// include
//----------------------------------------------------------------
#include <iostream>
#include <mutex>
#include <atomic>
#include <thread>
#include <functional>
#include <condition_variable>


using task_func = std::function<void (void *)>;
//----------------------------------------------------------------
// class TaskQueue
//----------------------------------------------------------------
class TaskQueue
{
public:
    struct task_t {
        task_t    *next{};
        task_func  func{};
        void      *arg {};
    };

public:
    TaskQueue();
    ~TaskQueue();

    void push_task(task_func func, void *arg);
    task_t * get_task();

private:


private:
    task_t                  *head_{};
    task_t                  *tail_{};
    std::atomic_uint32_t     cont_{0};
    std::mutex               mutex_{};

};


//----------------------------------------------------------------
// class ThreadPool
//----------------------------------------------------------------
class ThreadPool
{

public:
    explicit ThreadPool(int thread_cnt);
    ~ThreadPool();

    void push_tash(task_func func, void *arg);

private:
    void thread_task();
    void thread_destory();

private:
    std::atomic_bool           runing_{};
    std::vector<std::thread*>  thread_{};
    TaskQueue                 *task_queue_{};

    std::mutex                 mutex_{};
    std::condition_variable    condv_{};
};



#endif // __THREAD_POOL__
